<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Public:header2" />
    <title>{:C('web_title')}</title>
</head>
<body class="blackbg">
    <div id="container" class="logbg">
        <div class="log_title">
            <span class="back"><a href="javascript:history.go(-1)"></a></span>
            <if condition="$paypwd eq 0">{$Think.lang.Login_szjymm}<else />{$Think.lang.g_modify_tradepwd}</if>
        </div>
        <div class="logbot">
			<if condition="$paypwd eq 0">
				<input style="display:none;" type="password" class="logipt" id="oldpaypassword" placeholder="{$Think.lang.g_jiaoyimm}" onkeyup="chkpwd();" maxlength="16"/>
				<input type="password" id="newpaypassword" class="logipt" placeholder="{$Think.lang.User_jymmgs}" onkeyup="chknewpwd();" maxlength="16"/>
				<input type="password" id="repaypassword" class="logipt" placeholder="{$Think.lang.User_qrjymmgs}" onkeyup="rechknewpwd();" maxlength="16"/>
			<else />
				<input type="password" class="logipt" id="oldpaypassword" placeholder="{$Think.lang.User_jjymm}" onkeyup="chkpwd();" maxlength="16"/>
				<input type="password" id="newpaypassword" class="logipt" placeholder="{$Think.lang.Login_xjymm}" onkeyup="chknewpwd();" maxlength="16"/>
				<input type="password" id="repaypassword" class="logipt" placeholder="{$Think.lang.Login_qrjymm}" onkeyup="rechknewpwd();" maxlength="16"/>
			</if>
			<!--<select id="chkstyle" class="logipt">
				<option value="">请选择验证方式</option>
				<option value="mobile">手机号码验证</option>
				<option value="email">邮箱验证</option>
			</select>
			<div class="yzmbox" id="mobile_div" style="display:none;">
				<input type="text" id="mobile_verify" value="" class="logipt yzmipt" placeholder="短信验证码" />
				<input type="button" id="regBtn" onclick="SendCode()" value="点击获取验证码" class="phonebut" />
				<if condition="$user['mobile'] eq '' || $user['mobile'] eq null">
					<p class="attention">您没有绑定手机，请先绑定手机或换成其它验证方式</p>
				<else />
					<p class="attention">* 接收短信的手机{$user['mobile']|addstar=###,mobile}</p>
				</if>
			</div>-->
			<div class="yzmbox" id="email_div">
				<input type="text" id="email_verify" value="{$Think.lang.g_yx_verify}" class="logipt yzmipt" maxlength="6" />
				<input type="button" id="regBtn" onclick="EmCode()" value="{$Think.lang.Finance_hqyzm2}" class="phonebut" />
				<if condition="$user['email'] eq '' || $user['email'] eq null">
					<p class="attention">您没有绑定邮箱，请先绑定邮箱或换成其它验证方式</p>
				<else />
					<p class="attention">* {$Think.lang.g_pwd_yx_recode}{$user['email']|addstar=###,email}</p>
				</if>
			</div>
			<p class="attention">
				{$Think.lang.g_paypwd_notice}
			</p>
			<input type="button" class="logbut" id="btn-submit" value="{$Think.lang.User_save}" title="{$Think.lang.User_save}" onclick="Update()"/>
        </div>
    </div>
<script type="text/javascript">
  $("#chkstyle").change(function(){
    if($(this).val()=="mobile"){
      $("#mobile_div").show();
      $("#email_div").hide();
    }else if($(this).val()=="email"){
      $("#mobile_div").hide();
      $("#email_div").show();
    }
  });

  function SendCode() {
  layer.load(0, {shade: [0.5,'#8F8F8F']});
    $('#regBtn').attr("disabled", "disabled");
    $.post("{:U('Verify/paypass')}", {}, function (data) {
    layer.closeAll();
      if (data.status == 1) {
        layer.msg(data.info, {
          icon: 1
        });
        var obj = $('#regBtn');
        var wait = 120;
        var interval = setInterval(function () {
          obj.css('backgroundColor', '#f6f6f6');
          obj.val(wait + '秒再次发送');
          wait--;
          if (wait < 0) {
            obj.removeAttr("disabled");
            clearInterval(interval);
            obj.val('获取验证码');
            obj.css('backgroundColor', '#0096e0');
          }
          ;
        }, 1000);
      } else {
        $('#regBtn').removeAttr("disabled");
        layer.msg(data.info, {
          icon: 2
        });
      }
    }, "json");
  }

  function EmCode() {
  var chkstyle = 'email';
  if(!chkstyle || chkstyle != 'email'){
  layer.tips('您选择的验证方式不是邮箱验证', '#chkstyle', {
        tips: 3
    });
    return false;
  }
  layer.load(0, {shade: [0.5,'#8F8F8F']});
    $('#regBtn').attr("disabled", "disabled");
    $.post("{:U('Verify/paypwdemail')}", {}, function (data) {
    layer.closeAll();
      if (data.status == 1) {
        layer.msg(data.info, {
          icon: 1
        });
        var obj = $('#regBtn');
        var wait = 120;
        var interval = setInterval(function () {
          obj.css('backgroundColor', '#135f91');
          obj.val(wait + '{$Think.lang.sFinance_myzc_mzcfs}');
          wait--;
          if (wait < 0) {
            obj.removeAttr("disabled");
            clearInterval(interval);
            obj.val('{$Think.lang.sFinance_myzc_hqyzm}');
            obj.css('backgroundColor', '#135f91');
          }
          ;
        }, 1000);
      } else {
        $('#regBtn').removeAttr("disabled");
        layer.msg(data.info, {
          icon: 2
        });
      }
    }, "json");
}


  function Update(){
    var repaypassword = $("#repaypassword").val();
    var newpaypassword = $("#newpaypassword").val();
    var oldpaypassword = $("#oldpaypassword").val();
    //var mobile_verify = $("#mobile_verify").val();
    var chkstyle = 'email';
    var email_verify = $("#email_verify").val();
    var paypwd={$paypwd};
    if(!chkstyle){
      layer.tips('您选择验证方式！', '#chkstyle', {
        tips: 3
      });
      return false;
    }

    if (chkstyle == 'email' &&(email_verify == "" || email_verify == null)) {
      layer.tips('{$Think.lang.sFinance_myzc_qsryxyzm}', '#email_verify', {
        tips: 3
      });
      return false;
    }
/*    if (chkstyle == 'mobile' && (mobile_verify == "" || mobile_verify == null)) {
      layer.tips('请输入短信验证码', '#mobile_verify', {
        tips: 3
      });
      return false;
    }*/

    if  (paypwd == 1 && (oldpaypassword == "" || oldpaypassword == null)) {
      layer.tips('{$Think.lang.sFinance_myzc_qsrjymm}', '#oldpaypassword', {
        tips: 3
      });
      return false;
    }

    if (newpaypassword == "" || newpaypassword == null) {
      layer.tips('{$Think.lang.User_srnewjypw}', '#newpaypassword', {
        tips: 3
      });
      return false;
    }

     if (repaypassword == "" || repaypassword == null) {
      layer.tips('{$Think.lang.User_srenterpw}', '#repaypassword', {
        tips: 3
      });
      return false;
    }
	layer.load(0, {shade: [0.5,'#8F8F8F']});
    $.post("{:U('User/uppaypassword')}",{oldpaypassword : oldpaypassword,newpaypassword : $('#newpaypassword').val(),repaypassword : $('#repaypassword').val(),email_verify: email_verify,chkstyle:chkstyle },function(data){
		layer.closeAll();
      if(data.status==1){
        layer.msg(data.info,{icon : 1 });
        window.location="{:U('User/paypassword')}";
      }else{
        layer.msg(data.info,{icon : 2 });
        if(data.url){
          window.location=data.url;
        }
      }
    },"json");
  }

	function chkpwd(){
		var paypassword = $("#oldpaypassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(paypassword)) {
			layer.tips('{$Think.lang.sCommon_mmgs}','#oldpaypassword',{tips:3});
			var result = paypassword.substring(0,paypassword.length-1);
			$("#oldpaypassword").val(result);
		}
	}
	function chknewpwd(){
		var newpaypassword = $("#newpaypassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(newpaypassword)) {
			layer.tips('{$Think.lang.sCommon_mmgs}','#newpaypassword',{tips:3});
			var result = newpaypassword.substring(0,newpaypassword.length-1);
			$("#newpaypassword").val(result);
		}
	}
	function rechknewpwd(){
		var repaypassword = $("#repaypassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(repaypassword)) {
			layer.tips('{$Think.lang.sCommon_mmgs}','#repaypassword',{tips:3});
			var result = repaypassword.substring(0,repaypassword.length-1);
			$("#repaypassword").val(result);
		}
	}
	function chkyzm(){
		var mobile_verify = $("#mobile_verify").val();
		if(!mobile_verify){
			layer.tips('请填写短信验证码！','#mobile_verify',{tips:3});
			return false;
		}
	}
</script>
	<include file="Public:footer" />
</body>
</html>